package com.azxc.rapid.plus.system.service.impl;

import com.azxc.rapid.core.mp.base.BaseServiceImpl;
import com.azxc.rapid.core.tool.utils.BeanUtil;
import com.azxc.rapid.plus.system.entity.SystemInfoEntity;
import com.azxc.rapid.plus.system.excel.SystemInfoExcel;
import com.azxc.rapid.plus.system.mapper.SystemInfoMapper;
import com.azxc.rapid.plus.system.service.ISystemInfoService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * 系统配置信息 服务实现类
 */
@Service
public class SystemInfoServiceImpl extends BaseServiceImpl<SystemInfoMapper, SystemInfoEntity> implements ISystemInfoService {
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void importSystemInfo(List<SystemInfoExcel> data, Boolean isCovered) {
		data.forEach(systemInfoExcel -> {
			SystemInfoEntity systemInfo = Objects.requireNonNull(BeanUtil.copy(systemInfoExcel, SystemInfoEntity.class));
			this.submit(systemInfo);
		});
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean submit(SystemInfoEntity entity) {
		return save(entity);
	}

	@Override
	public List<SystemInfoExcel> exportSystemInfo(Wrapper<SystemInfoEntity> queryWrapper) {
		List<SystemInfoExcel> systemInfoList = baseMapper.exportSystemInfo(queryWrapper);
		return systemInfoList;
	}
}
